<template>
<div>
    <Card class="ivu-mb-16" v-width="250">
        <video :src="datas.path" width="100%" height="180px" controls></video>
        <Row type="flex" justify="space-between" class="ivu-mt-8">
            <Col v-if="!bool"><Button size="small"  @click="changedel(datas)" v-hasC="{name: '-v1-material-video-video-del',flag: '/v1/material/video/video-del'}">删除</Button></Col>
            <Col><Button size="small">视频大小：{{datas.size}}M</Button></Col>
            <Col><span ><Icon type="ios-eye-outline" />{{datas.click}}</span></Col>
        </Row>
        <div v-if="bool">
            <Row type="flex" align="middle" justify="space-between" class="ivu-mt-8">
                <Col><Button size="small" @click="changerealdel(datas)" v-hasC="{name: '-v1-material-img-img-completely-del',flag: '/v1/material/img/img-completely-del'}" type="error" ghost>彻底删除</Button></Col>
                <Col><Button size="small" @click="changereduction(datas)" type="warning" ghost  v-hasC="{name: '-v1-material-img-img-reduction',flag: '/v1/material/img/img-reduction'}">还原视频</Button></Col>
            </Row>
        </div>
        <div v-else>
            <div class="boxFotter ivu-mt-8 ivu-mb-8">
                <span>标签：</span>
                <Input v-model="datas.name" placeholder="请输入标签" style="width: 160px"  @on-blur="changeMark(datas)" />
            </div>
            <Button type="primary" style="width:100%"  @click="changeClick(datas)">复制链接</Button>
        </div>
    </Card>
</div>
</template>

<script>
    import { materialvideoaddremark, materialvideovideoadd, materialvideovideodel, materialimgimgcompletelydel, materialimgimgreduction } from '@/api/sourcematerial.js'
    export default {
        name: 'Cardvideo',
        props: {
            index: { type: [String, Number] },
            data: { type: Object },
            bool: { type: Boolean, default: false }
        },
        data () {
            return {
                datas: {}
            };
        },

        mounted () {
            this.datas = { ...this.data }
        },
        methods: {
            // 删除图片
            changedel (item) {
                this.$Modal.confirm({
                    title: '确定将当前视频删除移入回收站？',
                    onOk: () => {
                        materialvideovideodel({ id: item.id }).then(res => {
                            this.$Message.info('删除成功');
                            this.$emit('videodel', this.index);
                        })
                    }
                })
            },
            // 打标签
            changeMark (item) {
                let params = {
                    video_name: item.name,
                    id: item.id
                }
                materialvideoaddremark(params).then(res => {
                    this.$Message.success('标记成功');
                })
            },
            changeClick (item) {
                this.$Copy({ text: item.path })
                // materialvideovideoadd({ id: item.id }).then(res => {
                // })
            },
            // 彻底删除图片
            changerealdel (item) {
                this.$Modal.confirm({
                    title: '彻底删除该视频，将无法恢复！如果该视频外部站点有引用，将导致外网视频无法访问。',
                    onOk: () => {
                        let params = {
                            id: item.id,
                            type: 2
                        }
                        materialimgimgcompletelydel(params).then(res => {
                            this.$Message.info('删除成功');
                            this.$emit('videodel', this.index);
                        })
                    }
                })
            },
            // 还原视频或者图片
            changereduction (item) {
                this.$Modal.confirm({
                    title: '是否还原该视频?',
                    onOk: () => {
                        let params = {
                            id: item.id,
                            type: 2
                        }
                        materialimgimgreduction(params).then(res => {
                            this.$Message.info('还原成功');
                            this.$emit('videodel', this.index);
                        })
                    }
                })
            }
        }
    };
</script>

<style lang="less" scoped>
</style>
